:: 基于 Windows Visual Studio 2015 的 jimgutil 编译脚本
:: 可选参数:
::   /BUILD          - 编译项目
::   /ONLYBUILD      - 跳过生成项目工程文件,直接编译项目
:: author guyadong
@echo off 

echo make jimgutil VS2015 project
if not defined VS140COMNTOOLS (
	echo vs2015 NOT FOUND.
	exit /B -1
)
echo vs2015 found.
where cmake
if errorlevel 1 (
	echo cmake NOT FOUND.
	exit /B -1
)
echo cmake found
set sh_folder=%~dp0

SET OPT_BUILD=0
SET OPT_CMAKE=1

:: parse command arguments
:loop
IF x%1 == x GOTO :pare_end
IF /I "%1" == "/BUILD"      SET OPT_BUILD=1
IF /I "%1" == "/ONLYBUILD"  SET OPT_BUILD=1 && SET OPT_CMAKE=0 
SHIFT
GOTO :loop
:pare_end

SET project_folder=%sh_folder%project.vs2015
SET install_prefix=%sh_folder%release\jimgutil_windows_x86_64

IF %OPT_CMAKE% == 0 (
	PUSHD %project_folder%  || EXIT /B
	GOTO :cmake_build 
)

:: 生成项目工程文件
IF EXIST %project_folder% RMDIR %project_folder% /s/q 
MKDIR %project_folder% 
PUSHD %project_folder% || EXIT /B

if not defined VisualStudioVersion (
	echo make MSVC environment ...
	call "%VS140COMNTOOLS%..\..\vc/vcvarsall" x86_amd64
)

ECHO creating x86_64 Project for Visual Studio 2015 ...
cmake %sh_folder% -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=%install_prefix% 

:: 编译项目
:cmake_build

IF %OPT_BUILD% == 1 (
	cmake --build . --target install --config release
	IF ERRORLEVEL 0 copy %install_prefix%\bin\jimgutil.dll %sh_folder%..\jimgutil\src\main\resources\win32-x86-64
)
POPD
